import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {HttpClient} from '@angular/common/http';
import {Service} from '../../../server/server';
import {HintsService} from '../../../public/serve/hints/hints.service';


declare var $:any;

@Component({
  selector: 'app-innerindex-style-form',
  templateUrl: './innerindex-style-form.component.html',
  styleUrls: ['./innerindex-style-form.component.css']
})

export class InnerindexStyleFormComponent implements OnInit {

    //文内样式设置
    internalContentStyle = {
        markedRed:'<span class="indexing_a" style="color:red;">[CONTENT]</span>',
        highlight:'<span class="indexing_a" style="background-color:yellow;">[CONTENT]</span>',
        link:'<a href="#" class="indexing_a">[CONTENT]</a>',
    }
    //默认
    internalContentVal : string = 'highlight';

    right: any = {
        "systemInnerindexStyle": {},
    };

    constructor( private http: HttpClient, private hintsService: HintsService, private server: Service, private router: Router) {
        this.right = $.extend(this.right, server.getRight());
    }

    ngOnInit() {
        this.getInnerIndexStyleInfo();
    }

    saveInnerIndexStyleInfo(info){
        let tagName = info.innerindex_style;
        let url = this.server.baseUrl + 'Service/Config/saveIndexingTag';
        let data = {
            "tagId": "b25dbd7138cf48e09941087e6d9a2e93",
            "tagName": tagName,
            "tagStyle": this.internalContentStyle[tagName],
            "updateBy": this.server.getuserName()
        }

        this.http.post(url, data)
            .subscribe(res => {
                if (res['result_code']== '0000') {
                    this.internalContentVal = tagName;
                    this.server.prompt = { prompt: true, success: true, fail: false, promptStatement: res['message'] };
                    this.server.promptclose;
                } else {
                    this.server.prompt = { prompt: true, success: false, fail: true, promptStatement: res['message'] };
                    this.server.promptclose;
                }

                this.hintsService.messages(res['message'], res['result_code']);
            });
    }

    // 表格
    getInnerIndexStyleInfo() {
        let url = this.server.baseUrl + 'Service/Config/getIndexingTag';
        let data = {
        }
        //console.log(data)
        this.http.post(url, data)
            .subscribe(res => {
                //console.log(res)
                if (res['result_code']== '0000') {
                    let result = res['result'];
                    if(result){
                        this.internalContentVal = result[0]['tagName'];
                    }
                    this.server.prompt = { prompt: true, success: true, fail: false, promptStatement: res['message'] };
                    this.server.promptclose;
                } else {
                    this.server.prompt = { prompt: true, success: false, fail: true, promptStatement: res['message'] };
                    this.server.promptclose;
                }
            });
    }
}
